﻿<UserControl x:Class="Wpf2.Views.AddInventory"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Wpf2.Models"
             mc:Ignorable="d" Width="Auto" Height="700">
    <UserControl.Resources>
        <local:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    </UserControl.Resources>
    <StackPanel Width="Auto" Orientation="Vertical" Height="Auto"   Margin="0,0,0,50">
        <StackPanel Width="Auto" Height="50" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Margin="5,5,0,0" >
            <StackPanel Width="Auto" Orientation="Horizontal">
                <ListView MaxWidth="1200" Width="Auto" Height="50" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" HorizontalAlignment="Left"  Name="lvCatalog" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectedIndex="0" BorderThickness="0">
                    <ListView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"></StackPanel>
                        </ItemsPanelTemplate>
                    </ListView.ItemsPanel>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Border BorderBrush="Blue" BorderThickness="1" Height="30" Background="#FF16499A" >
                                <StackPanel Orientation="Horizontal" Height="30" Width="120" HorizontalAlignment="Center">
                                    <Image Source="/Wpf2;component/Images/catalog.png" Width="30" Height="30"/>
                                    <TextBlock Text="{Binding CatalogName}" VerticalAlignment="Center" Margin="2,0,0,0" Foreground="White"/>
                                </StackPanel>
                            </Border>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackPanel>
        </StackPanel>
        <Border Height="48" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Margin="5,5,0,5">
            <StackPanel Orientation="Horizontal"  Margin="5,5,5,5" HorizontalAlignment="Right">
                <StackPanel  Margin="10,0,10,0" Height="30" Width="120" Orientation="Horizontal" Background="#FF16499A">
                    <Label Background="#FF0050EF" Foreground="White">Đá hoa cương</Label>
                    <CheckBox Name="chkDahoacuong" Height="30" Margin="8,7,5,5" IsChecked="{Binding IsMarble, UpdateSourceTrigger=PropertyChanged}" Checked="CaculationPayment" Unchecked="CaculationPayment"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Height="30">
                    <Label Content="_Mã nhân viên" Target="{Binding ElementName=txtUserID}" Background="#FF0050EF" Foreground="White"/>
                    <TextBox  Background="#FF0050EF" Padding="5" Margin="0,0,20,0" Height="30" Width="100" Name="txtUserID" Text="{Binding ID_USER,UpdateSourceTrigger=PropertyChanged}" PreviewTextInput="TxtInventoryCountPreviewTextInput" Foreground="#FFFCFCFC" ></TextBox>
                </StackPanel>
                <StackPanel Margin="0,0,20,0" Width="120" Height="30" Orientation="Horizontal">
                    <Button x:Name="btnSaveAddInvetory"  Width="90" Background="#FF16499A">
                        <TextBlock Foreground="#FFFCFCFC"> Lưu</TextBlock>
                    </Button>
                    <StackPanel Width="30" Height="30" Background="#FF0050EF">
                        <Image Source="/Wpf2;component/Images/Save.png" />
                    </StackPanel>
                </StackPanel>
                <StackPanel Margin="0,0,20,0" Width="120" Height="30" Orientation="Horizontal">
                    <Button x:Name="btnPrint"  Width="90" Background="#16499A" >
                        <TextBlock Foreground="#FFFCFCFC"> In</TextBlock>
                    </Button>
                    <StackPanel Width="30" Height="30" Background="#FF0050EF">
                        <Image Source="/Wpf2;component/Images/print.png" />
                    </StackPanel>
                </StackPanel>
            </StackPanel>
        </Border>
        <DataGrid x:Name="dtgInventory" Background="White"  Height="383" AutoGenerateColumns="False" CanUserAddRows="False" Margin="5,5,5,0" AlternatingRowBackground="#90d3d9">
            <DataGrid.RowHeaderTemplate>
                <DataTemplate>
                    <TextBlock  Width="20" Text="{Binding Header, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}, Mode=FindAncestor}}"/>
                </DataTemplate>
            </DataGrid.RowHeaderTemplate>

            <DataGrid.Columns>
                <DataGridTemplateColumn Header="Mã SP" Width="80">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid VerticalAlignment="Bottom" HorizontalAlignment="Center">
                                <TextBox Height="20" Width="150" TextChanged="TxtProductNameTextChanged" Text="{Binding ProductId, UpdateSourceTrigger=PropertyChanged}" LostFocus="TxtProductNameLostFocus" BorderThickness="0" KeyDown="TxtProductNameKeydown" Background="{x:Null}" />
                                <ComboBox SelectionChanged="ComboBoxSelectionChanged" Visibility="Hidden"  IsTabStop="False" IsSynchronizedWithCurrentItem="True" />
                            </Grid>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Width="150" Header="Tên Sản Phẩm" Binding="{Binding ProductName, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True" CanUserSort="False"/>

                <DataGridTextColumn Width="100" Header="Mô Tả" Binding="{Binding ProductDescription, UpdateSourceTrigger=PropertyChanged}"  IsReadOnly="True" CanUserSort="False"/>
                <!-- BeginRegion-->
                <!-- DataGird không thể sử dụng elementName => phải dùng Source-->
                <!-- hiện lỗi không sao! cứ bỏ qua-->
                <!-- Xử lý dạng Đá Hoa Cương (9/5/2014)-->
                <DataGridTemplateColumn Header="Dài" Width="50" IsReadOnly="True" CanUserSort="False" Visibility="{Binding Source={x:Reference chkDahoacuong}, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding ProductHeight, UpdateSourceTrigger=LostFocus}" LostFocus="CaculationPayment" BorderThickness="0"  Background="{x:Null}"></TextBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Rộng" Width="50" IsReadOnly="True" CanUserSort="False" Visibility="{Binding Source={x:Reference chkDahoacuong}, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding ProductWidth, UpdateSourceTrigger=LostFocus}" LostFocus="CaculationPayment" BorderThickness="0" Background="{x:Null}"></TextBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <!-- EndRegion-->
                <DataGridTemplateColumn Header="Số Lượng">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding InventoryCount, UpdateSourceTrigger=PropertyChanged}" PreviewTextInput="TxtInventoryCountPreviewTextInput" BorderThickness="0" Background="{x:Null}" TextChanged="TxtInventoryTextChanged"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Header="M2" Binding="{Binding ProductM2, UpdateSourceTrigger=PropertyChanged}" Width="80" IsReadOnly="True" CanUserSort="False" Visibility="{Binding Source={x:Reference chkDahoacuong}, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                <DataGridTextColumn Width="100" Header="Giá" Binding="{Binding CostPrice, StringFormat=\{0:###\,##0\} VNĐ, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True"  CanUserSort="False"/>
                <DataGridTextColumn Width="100" Header="Đơn Vị" Binding="{Binding unit.unitName, UpdateSourceTrigger=PropertyChanged}"  IsReadOnly="True" CanUserSort="False"/>
                <DataGridTextColumn Width="100" Header="Nhóm" Binding="{Binding catalog.CatalogName, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True"  CanUserSort="False"/>
                <DataGridTextColumn Header="Thành tiền" Binding="{Binding TotalInPayment, StringFormat=\{0:###\,##0\} VNĐ, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True" Width="*" CanUserSort="False"/>

            </DataGrid.Columns>

        </DataGrid>
        <StackPanel Height="57"  Background="#FFF6F6F6" Margin="5">
            <StackPanel Orientation="Horizontal" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"  Margin="0,5,0,10" VerticalAlignment="Center" Height="50" Grid.Row="1" HorizontalAlignment="Right">
                <Label Height="30"  Content="Tổng cộng: " Background="#FF0050EF" Foreground="White"/>
                <TextBox Height="30"  Padding="5" Name="txtTotalPayment" IsEnabled="False" Width="120" Foreground="White" Background="#FF0050EF"></TextBox>
            </StackPanel>
        </StackPanel>

    </StackPanel>
</UserControl>
